package cn.com.bonc.khjy.date.mapper.dataSource1;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
public interface CommonMapper1 {

    @Select("SELECT topic_name FROM epm_kafka_topics ")
    List<String> getTopic();

    @Select("SELECT ACTIVITY_CODE,ACTIVITY_NAME, ACTIVITY_START_DATE, ACTIVITY_END_DATE,ACTIVITY_CREATE_NAME,\n" +
            "    CASE ACTIVITY_TYPE_CODE\n" +
            "        WHEN '0' THEN '一次性'\n" +
            "        WHEN '1' THEN '按月刷新'\n" +
            "        ELSE  '按日刷新'\n" +
            "      END\n" +
            "        AS TYPE,\n" +
            "    CASE STATUS_CODE\n" +
            "        WHEN '04' THEN '审批通过'\n" +
            "        WHEN '05' THEN '启用'\n" +
            "        WHEN '06' THEN  '暂停'\n" +
            "        ELSE '停用'\n" +
            "      END\n" +
            "    AS STATUS\n" +
            "    FROM epm_activity_info\n" +
            "    WHERE (STATUS_CODE = '04' OR STATUS_CODE = '05' OR STATUS_CODE = '06' OR STATUS_CODE = '07')\n" +
            "    AND ACTIVITY_NAME LIKE CONCAT('%',#{activityName},'%')\n" +
            "    ORDER BY ACTIVITY_CREATE_TIME DESC limit #{start},#{end}")
    @ResultType(Map.class)
    List<Map<String,Object>> getBaseActivityList( @Param( "start" ) Integer start, @Param( "end" ) Integer end, @Param( "activityName" ) String activityName );

    @Select(" SELECT NODE_CONTENT FROM epm_activity_node_info WHERE ACTIVITY_CODE = #{ACTIVITY_CODE}\n" +
            "        AND ASSEMBLY_ID='customerGroupConfig';")
    @ResultType(String.class)
    String getCustomerCount( @Param( "ACTIVITY_CODE" ) String activity_code );

    @Select("SELECT MAIN.ACTIVITY_NAME, MAIN.ACTIVITY_START_DATE, MAIN.ACTIVITY_END_DATE,\n" +
            "    CASE MAIN.ACTIVITY_TYPE_CODE\n" +
            "        WHEN '0' THEN '一次性'\n" +
            "        WHEN '1' THEN '按月刷新'\n" +
            "        ELSE  '按日刷新'\n" +
            "      END\n" +
            "        AS TYPE,T.LEVEL_NAME\n" +
            "    FROM epm_activity_info MAIN\n" +
            "    LEFT JOIN epm_activity_theme_info T\n" +
            "    ON MAIN.LEVEL_ID = T.LEVEL_ID\n" +
            "    WHERE MAIN.ACTIVITY_CODE = #{ACTIVITY_CODE}")
    @ResultType(Map.class)
    Map<String,Object> getBaseActivityInfo( @Param( "ACTIVITY_CODE" ) String activity_code );

    @Select(" SELECT * FROM epm_activity_node_info WHERE ACTIVITY_CODE = #{ACTIVITY_CODE}\n" +
            "       AND ASSEMBLY_ID = 'subCustomerGroupConfig'")
    @ResultType(Map.class)
    List<Map<String, Object>> getSubCustomerGroupInfo( @Param( "ACTIVITY_CODE" ) String activityCode );

    @Select(" SELECT NEXT_NODE_ID FROM epm_activity_flow_info WHERE NODE_ID = #{nodeId}")
    @ResultType(String.class)
    String getStrategyNodeId( @Param( "nodeId" ) String nodeId );

    @Select("SELECT NODE_CONTENT FROM epm_activity_node_info WHERE NODE_ID = #{nodeId}")
    @ResultType(String.class)
    String getStrategyInfo( @Param( "nodeId" ) String strategyNodeId );

    @Select("SELECT NEXT_NODE_ID FROM epm_activity_flow_info WHERE NODE_ID = #{nodeId}")
    @ResultType(String.class)
    String getChannelNodeId( @Param( "nodeId" ) String strategyNodeId );

    @Select(" SELECT NODE_CONTENT FROM epm_activity_node_info WHERE NODE_ID = #{nodeId}")
    @ResultType(String.class)
    String getChannelInfo( @Param( "nodeId" ) String channelNodeId );

    @Select(" SELECT NODE_CONTENT FROM epm_activity_node_info WHERE ACTIVITY_CODE = #{ACTIVITY_CODE}\n" +
            "        AND ASSEMBLY_ID = 'customerGroupConfig'")
    @ResultType(String.class)
    String getCustomerGroupInfo( String activityCode );
}
